{template 'common/header'}
<div class="nav nav-tabs">
    <ul class="nav nav-tabs">
        <li {if $opp == 'cards'}class="active"{/if}><a href="{php echo $this->createWebUrl('cards');}">名片管理</a></li>
        <li {if $opp == 'indus'}class="active"{/if}><a href="{php echo $this->createWebUrl('indus');}">行业设置</a></li>
        <!-- <li {if $opp == 'card_overrule'}class="active"{/if}><a href="{php echo $this->createWebUrl('card_overrule');}">顶置设置</a></li> -->
        <!-- <li {if $opp == 'videosetup'}class="active"{/if}><a href="{php echo $this->createWebUrl('videosetup');}">视频设置</a></li> -->
        <!-- <li {if $opp == 'wxacode'}class="active"{/if}><a href="{php echo $this->createWebUrl('wxacode');}">专属二维码设置</a></li> -->
    </ul>
</div>
<div class='container' style='padding:0 5px 10px;margin:0;width:100%'>
    <ul class="nav nav-tabs">
        <li {if $op == 'post'}class="active"{/if}><a href="{php echo $this->createWebUrl('cards', array('op' => 'post'));}">添加名片</a></li>
        <li {if $op == 'display'}class="active"{/if}><a href="{php echo $this->createWebUrl('cards',array('op'=>'display'));}">管理名片</a></li>
    </ul>
    {if $op =='display'}
    <div class="panel panel-success">
        <div class="panel-heading">名片通讯录 >名片管理</div>
    </div>
    <div class="panel panel-info">
        <div class="panel-heading">筛选</div>
        <div class="panel-body">
            <form action="./index.php" method="get" class="form-horizontal" role="form">

                <input type="hidden" name="c" value="site" />

                <input type="hidden" name="a" value="entry" />

                <input type="hidden" value="bbyscm_card" name="m">

                <input type="hidden" value="cards" name="do">

                <input type="hidden" value="display" name="op">

                <div class="form-group">

                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">选择行业</label>

                    <div class="col-sm-4">

                        <select name="cid1"  class="form-control">

                            <option value=""></option>
                            {php $cates1 = pdo_fetchall("SELECT * FROM ".tablename('bbyscm_card_indus')." where uniacid=$uniacid");}

                            {php $cate1  = pdo_fetchall("SELECT * FROM ".tablename('bbyscm_card')." where uniacid=$uniacid");}

                            {loop $cates1 $catelist1}

                            <option value="{$catelist1['id']}" {if $_GPC['cid1']==$catelist1['id']}selected{/if}>{$catelist1['name']}</option>

                            {/loop}
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2  control-label">关键字</label>
                    <div class="col-sm-4">
                        <input type="text" placeholder="搜索姓名或手机号" value="{$_GPC['keyword']}" id="" name="keyword" class="form-control">
                    </div>				
                </div>
                <div class="form-group">
                    <div class="pull-right col-xs-12 col-sm-2">
                        <button class="btn btn-block"><i class="fa fa-search"></i> 搜索</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <div style="padding:15px;">

        <form id="form2" class="form-horizontal" method="post">

            <table class="table table-hover">

                <thead class="navbar-inner">

                    <tr>

                        <th style="width:90px;">全选</th>

                        <th style="width:60px;">ID</th>

                        <th style="width:100px;">姓名</th>

                        <th style="width:120px;">手机号</th>

                        <th style="width:100px;">行业</th>

                        <th style="width:50px;">性别</th>

                        <th style="width:60px;">头像</th>

                        <th style="width:100px;">时间</th>

                        <th style="min-width:60px;width:200px;">
                            <!-- 解绑 | 封号 |  -->
                            修改 |  删除</th>

                    </tr>

                </thead>

                <tbody>
                {loop $list $item}

                {php $cates = pdo_fetch("SELECT * FROM ".tablename('bbyscm_card_indus')." WHERE id='".$item['industry']."'");}

                <tr>

                    <td><input type="checkbox" value="{$item['id']}" name="delete[]"></td>

                    <td>{$item['id']}</td>

                    <td><a title='姓名:<?php echo (empty($item['cardname']))?'':"".$item['cardname'].""; ?>&#13;职务:<?php echo $item['job'];

                            echo "&#13;公司名称:".$item['company']."&#13;手机:".$item['mobile']."&#13;公司地址:".$item['address']."&#13;微信昵称:".$item['username']."&#13;公司电话:".$item['mobile2']."&#13;公司业务:".$item['desc'];

                            ?>' href="javascript:;">{$item['cardname']}</a></td>

                    <td>{$item['mobile']}</td>

                    <td>{$cates['name']}</td>

                    <td><?php echo $sexarr[$item["sex"]]; ?></td>

                    <td>{if !empty($item['avater'])}<img src="{$item['avater']}" width="50" height="50" />{else}<i class="fa fa-picture-o fa-2x"></i>{/if}</td>

                    <td>{php echo date('m-d H:i',$item['createtime'])}</td>

                    <td>

                        {if empty($item['openid'])}

                        <!--		<a href="javascript:alert('还没有绑定');" class="btn btn-sm btn-danger"><i class="fa fa-user" title="未绑定"></i></a>  -->	

                        <!-- <a href="javascript:;" onclick="isbd({$item['id']},0)" title="绑定" class="btn btn-sm btn-danger"><i class="fa fa-user"></i></a> -->
                        {else}

                        <!-- <a href="javascript:;" onclick="isjb({$item['id']},0)" title="解绑" class="btn btn-sm btn-success"><i class="fa fa-user"></i></a> -->

                        {/if}	

                        <!-- <a id="id{$item['id']}" href="javascript:shen('{php echo $this->createWebUrl('cards', array('op' => 'shenhe', 'id' =>$item['id'],'akey'=>$item['akey']))}',{$item['id']});" title="{if $item['akey']==0}封号{else}解封号{/if}" class="shen btn btn-sm {if $item['akey']==1}btn-danger{else}btn-success{/if}"><i class="fa fa-check"></i></a> -->

                        <a href="{php echo $this->createWebUrl('cards', array('op' => 'post', 'id' => $item['id']))}" title="编辑" class="btn btn-primary btn-sm"><span class="fa fa-edit"></span></a>

                        <a onclick="return confirm('此操作不可恢复，确认吗？'); return false;" href="{php echo $this->createWebUrl('cards', array('id' => $item['id'],'op'=>'del'))}" title="删除" class="btn btn-sm btn-danger"><span class="fa fa-times" ></span></a>

                    </td>				

                </tr>

                {/loop}

                <tr >

                    <td><input type="checkbox"  onclick="var ck = this.checked;$(':checkbox').each(function(){this.checked = ck});" name=''>    <input class="btn btn-primary btn-sm" type="submit" value="删除" name="submit" ></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td>

                </tr>

                </tbody>

            </table>

            <input type="hidden" value="card" name="do">

            <input type="hidden" value="del" name="op">

            <input type="hidden" name="token" value="{$_W['token']}" />

        </form>

        {$pager}

        <script>

function shen(url,id){

    $.getJSON(url,function(data){

        if(data.a==0){

            $("#id"+id).removeClass('btn-success');

            $("#id"+id).addClass('btn-danger');

        }else if(data.a==1){

            $("#id"+id).removeClass('btn-danger');

            $("#id"+id).addClass('btn-success');

        }

        location.reload();

    })

}

function isjb(id){

    $.ajax({

        type: "POST",

        url:  "{php echo $this->createWebUrl('cards', array('op' => 'jb'))}",

        data: "id="+id,

        dataType:"json",

        success: function(msg){

            if(msg.status == true)

                {alert('解绑成功');

                    location.reload();

                }

                else

                    {

                        alert('解绑失败');

                    }

        }

    }); 

}
function isbd(id){

    $.ajax({

        type: "POST",

        url:  "{php echo $this->createWebUrl('accredit', array('op' => 'bd'))}",

        data: "id="+id,

        dataType:"json",

        success: function(msg){
            var url = msg.imgUrl;
            if(msg.status == true)

                {
                    //   alert($('#tuserlink').html('<img  src = '+ url +' style="sposition:relative">'););
                    $('#Modal2').modal('toggle');
                    $('#tuserlink').html('<img  src = '+ url +'>');
                    // location.reload(); 

                }

                else

                    {

                        alert('绑定失败');


                    }

        }

    }); 

}
        </script>

        <script>


$('#form2').submit(function(){

    if($(":checkbox[name='delete[]']:checked").size() > 0){

        return confirm('删除后不可恢复，您确定删除吗？');

    }

    return false;

}); 

        </script>	

    </div>

    <div class="modal fade" id="Modal2"  >

        <div class="modal-dialog">

            <div class="modal-content" >
                <div class="modal-header">
                    <h4 class="modal-title" style="text-align: center;">微信扫描二维码绑定</h4>
                </div>
                <div class="modal-body"  id='tuserlink' style="text-align: center;"></div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-danger" data-dismiss="modal">关闭</button>
                </div>
            </div><!-- /.modal-content -->

        </div><!-- /.modal-dialog -->

    </div><!-- /.modal -->

    {elseif $op == 'post'}
    <div class="panel panel-success">
        <div class="panel-heading">名片通讯录 >添加名片</div>
    </div>

    <div class="main">

        <form action="" method="post" class="form-horizontal form">

            <div class="panel panel-default">

                <div class="panel-heading">

                    添加/修改名片

                </div>

                <div class="panel-body">

                    <div class="form-group">

                        <label class="col-sm-2 control-label">姓名<span style="color:red;font-size:18px">*</span></label>

                        <div class="col-sm-7">

                            <input type="text" name="cardname" class="form-control" value="{$item['cardname']}" /> 



                        </div>

                    </div>

                    <div class="form-group">

                        <label class="col-sm-2 control-label">手机号<span style="color:red;font-size:18px">*</span></label>

                        <div class="col-sm-7">

                            <input type="text" name="mobile" class="form-control" value="{$item['mobile']}" /> 				

                        </div>

                    </div>
                    <div class="form-group hidden">

                        <label class="col-sm-2 control-label">OPENID<span style="color:red;font-size:18px">*</span></label>

                        <div class="col-sm-7">

                            <label type="text" name="openid" class="form-control" value="{$item['openid']}">{$item['openid']}</label>

                            <span class="help-block" style="color:red;font-size:18px">此处不用填写也不许改动，</span>		

                        </div>

                    </div>

                    <div class="form-group">

                        <label  class="col-sm-2 control-label">头像图片</label>

                        <div class="col-sm-7">

                            {php echo tpl_form_field_image('avater', $item['avater'] =='' ? $setting['thumb'] : $item['avater']);}

                            <span class="help-block">头像图片,大小100X100之内,可以不填,将采用自动同步微信头像</span>

                        </div>

                    </div>
                    <div class="form-group">

                        <label  class="col-sm-2 control-label">图片介绍</label>

                        <div class="col-sm-7">

                            {php echo tpl_form_field_multi_image('imgs', $item['imgs']);}

                        </div>

                    </div>
                    <div class="form-group hidden">

                        <label  class="col-sm-2 control-label">二维码</label>

                        <div class="col-sm-7">

                            {php echo tpl_form_field_image('bp_qr', $item['bp_qr'] =='' ? $setting['thumb'] : $item['bp_qr']);}

                            <span class="help-block">只用做后台预览，可以删除，用户再次点击时重新生成</span>

                        </div>

                    </div>
                    <div class="form-group hidden">

                        <label  class="col-sm-2 control-label">专属二维码</label>

                        <div class="col-sm-7">

                            {php echo tpl_form_field_image('qrcode', $item['qrcode'] =='' ? $setting['thumb'] : $item['qrcode']);}

                            <span class="help-block">只用做后台预览，可以删除，用户再次点击时重新生成</span>

                        </div>

                    </div>
                    <div class="form-group">

                        <label class="col-xs-12 col-sm-3 col-md-2 control-label">分组</label>

                        <div class="col-sm-7">

                            <select name="mail_id"  class="form-control">

                                <?php

                                $itemarr =  pdo_fetchall("SELECT *  FROM ".tablename('bbyscm_card_mail') ."  where  uniacid='$uniacid' ORDER BY id ASC"); 

                                foreach($itemarr as $k2=>$v2){

                                $selected2 = ($item["ai_card"]==$v2['id'])?"selected":"";

                                echo "<option value='".$v2['id']."' $selected2  >".$v2['mail_name']."</option>";

                                }

                                ?>

                            </select>

                        </div>

                    </div>
                    <div class="form-group">

                        <label class="col-xs-12 col-sm-3 col-md-2 control-label">行业</label>

                        <div class="col-sm-7">

                            <select name="industry"  class="form-control">

                                <?php

                                $itemarr =  pdo_fetchall("SELECT *  FROM ".tablename('bbyscm_card_indus') ."  where  uniacid='$uniacid' ORDER BY id ASC"); 

                                foreach($itemarr as $k2=>$v2){

                                $selected2 = ($item["industry"]==$v2['id'])?"selected":"";

                                echo "<option value='".$v2['id']."' $selected2  >".$v2['name']."</option>";

                                }

                                ?>

                            </select>

                        </div>

                    </div>

                    <div class="form-group">

                        <label class="col-xs-12 col-sm-3 col-md-2 control-label">性别</label>

                        <div class="col-sm-7">

                            <select name="sex"  class="form-control">

                                <?php  

                                foreach($sexarr as $k1=>$v1){

                                $selected1 = ($item["sex"]==$k1)?"selected":"";

                                echo "<option value='$k1' $selected1  >$v1</option>";

                                }

                                ?>

                            </select>

                        </div>

                    </div>

                    <div class="form-group">

                        <label class="col-sm-2 control-label">职务</label>

                        <div class="col-sm-7">

                            <select name="job1"  class="form-control hidden">

                                <option value=''   >    </option>

                                <?php  

                                foreach($job1 as $k3=>$v3){

                                $selected3 = ($item["job"]==$v3)?"selected":"";

                                echo "<option value='$v3' $selected3  >$v3</option>";

                                }

                                ?>

                            </select>

                            <input type="text" name="job" class="form-control" value="{$item['job']}" />

                            <!-- <span class="help-block">如果列表中没有你要的职务,请填写</span>				 -->

                        </div>

                    </div>

                    <div class="form-group">

                        <label class="col-sm-2 control-label">公司名称</label>

                        <div class="col-sm-7">

                            <input type="text" name="company" class="form-control" value="{$item['company']}" />

                            <!-- <span class="help-block">默认的公司名称</span> 				 -->

                        </div>

                    </div>			

                    <div class="form-group">

                        <label class="col-sm-2 control-label">Email</label>

                        <div class="col-sm-7">

                            <input type="text" name="email" class="form-control" value="{$item['email']}" /> 				

                        </div>

                    </div>	

                    <div class="form-group hidden">

                        <label class="col-sm-2 control-label">微信号</label>

                        <div class="col-sm-7">

                            <input type="text" name="weixin" class="form-control" value="{$item['weixin']}" /> 				

                        </div>

                    </div>				

                    <div class="form-group">

                        <label class="col-sm-2 control-label">公司电话</label>

                        <div class="col-sm-7">

                            <input type="text" name="mobile2" class="form-control" value="{$item['mobile2']}" /> 				

                        </div>

                    </div>			

                    <div class="form-group">

                        <label class="col-sm-2 control-label">公司地址</label>

                        <div class="col-sm-7">

                            <input type="text" name="address" class="form-control" value="{$item['address']}" /> 				

                        </div>

                    </div>


                    <div class="form-group">

                        <label class="col-sm-2 control-label">公司业务</label>

                        <div class="col-sm-7">

                            <textarea class="form-control" name="desc" rows="5">{$item['desc']}</textarea>

                            <span class="help-block">请不要输入过长文字,简单扼要介绍业务,50字以内</span>				

                        </div>

                    </div>

                    <div class="form-group">

                        <label class="col-sm-2 control-label">公司地图坐标</label>

                        <div class="col-sm-7">

                            <?php 

                            if(empty($item["longitude"])){

                            $map = array('lng'=>116.406955,'lat'=>39.913397);

                            }else{

                            $map =  array('lng'=>$item["longitude"],'lat'=>$item["latitude"]);

                            }

                            echo tpl_form_field_coordinate('g_map',$map);

                            ?>

                        </div>

                    </div>

                    <div class="form-group hidden">

                        <label class="col-sm-2 control-label">点击率</label>

                        <div class="col-sm-7">

                            <input type="text" name="popularity" class="form-control" value="{$item['popularity']}" /> 				

                        </div>

                    </div>

                    <div class="form-group hidden">

                        <label class="col-sm-2 control-label">分享值</label>

                        <div class="col-sm-7">

                            <input type="text" name="p_share" class="form-control" value="{$item['p_share']}" /> 				

                        </div>

                    </div>	

                    <div class="form-group hidden">

                        <label class="col-sm-2 control-label">帐户余额</label>

                        <div class="col-sm-7">

                            <input type="text" name="money" class="form-control" value="{$item['money']}" /> 				

                        </div>

                    </div>	
                    <div class="form-group">

                        <label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label"></label>

                        <div class="col-sm-4">

                            <input type="hidden" name="id" value="{$item[id]}">

                            <input type="hidden" name="token" value="{$_W['token']}" />

                            <input name="submit" type="submit" value="提交" class="btn btn-primary span3" />
                        </div>
                    </div>
                </div>
            </div>

        </form>
    </div>
    {/if}	
</div>
{template 'common/footer'}
